package src.mian.java;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ReadHDFSFile {
    public static void main(String[] args) {
        String hdfsUri = "hdfs://192.168.254.100:8020"; // 替换成您的 HDFS URI
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", hdfsUri);

        try {
            FileSystem fs = FileSystem.get(conf);
            Path filePath = new Path("/test/world.txt"); // 替换成您要查看的文件路径
            FSDataInputStream inputStream = fs.open(filePath);
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line); // 打印文件内容
            }

            reader.close();
            fs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
